import axios from 'axios'
import { getEnvParams } from '../tools/index';

const HTTP = axios.create({
  baseURL: process.env.VUE_APP_HTTP_BASE_URL,
})
/**
 * 请求拦截
 */
HTTP.interceptors.request.use(
  (request) => {
    let token = getEnvParams().token
    if (token) {
      request.headers.Authorization = `bearer ${token}`
    }
    return request
  },
)
/**
 * 响应拦截
 */
HTTP.interceptors.response.use(
  (response) => {
    if (response.status === 200) {
      return response.data
    }
  },
  (error) => {
    let res = JSON.parse(JSON.stringify(error));
    if (res.response.status === 401) {
      //
    }
    throw res
  },
)
const createAxios = () => {
  return axios.create({})
}
export { createAxios, HTTP }
